<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :showAttrs="showAttrs"
                :adviceNoteFunc="adviceNoteFunc"
    >
      <template v-slot:foot="{scope}">

        <el-tooltip class="item" effect="dark" content="发货通知" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button type="danger" size="small" icon="el-icon-truck" @click="deliveryOrderDetail(scope.row.id)"></el-button>
        </el-tooltip>

        <el-tooltip class="item" effect="dark" content="修改订单状态" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button type="primary" icon="el-icon-brush" size="small" @click="openOrderStatusDialog(R.prop('row', scope))"></el-button>
        </el-tooltip>

      </template>


    </table-view>
    <el-dialog
      title="选择当前订单的状态"
      :visible.sync="dialogVisible"
      width="30%">
      <el-radio-group v-model="status">
        <el-radio border :label="-1">预排</el-radio>
        <el-radio border :label="0">待配货</el-radio>
        <el-radio border :label="1">暂时下线</el-radio>
        <el-radio border :label="2">加急</el-radio>
        <el-radio border :label="3">正常</el-radio>
        <el-radio border :label="4">生产中</el-radio>
        <el-radio border :label="5">生产完成</el-radio>
        <el-radio border :label="90">客户待确认</el-radio>
        <el-radio border :label="99">取消</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderStatus">确 定</el-button>
      </span>
    </el-dialog>

    <multiple-dialog ref="multipleDialog" :tableListData="tableListData" ></multiple-dialog>
  </div>
</template>

<script>
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import {mRequest} from '@/utils/request'
import multipleDialog from '@/components/multipleDialog'
export default {
  mixins: [basicMixins],
  data() {
    return {
      dialogVisible: false,
      orderPlanNoticeVisible: false,
      tableListData: [],
      status: 0,
      searchAttrs: {
        productNo: {
          label: '商品信息',
          width: 140,
          type: 'linkLabel',
          searchKey: 'productNo',
          routerName: 'product-product-info-all'
        },
        clientId: {
          label: '客户名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入客户名称',
          querySearchApiName: 'clientApi/getClientList'
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'orderApi/listOrderDetailFinish',
      showAttrs: {
        orderNo: {
          label: '订单编号',
          width: 140,
          type: 'labelWithStatus',
          statusAttr: 'messageStatus',
          items: [
            {value: 0, text: '未读', tagType: 'danger'}
          ]
        },
        status: {
          label: '状态',
          type: 'radio',
          width: 110,
          items: [
            {value: 11, text: '出库完成', tagType: 'warning'},
            {value: 10, text: '出库中', tagType: 'primary'},
            {value: 5, text: '光瓶生产完成', tagType: 'success'},
            {value: 99, text: '取消', tagType: 'danger'}
          ]
        },
       // orderTime: {label: '订单时间', type: 'date', width: 100},
        clientName: {label: '客户'},
        productNo: {
          label: '产品编号',
          type: 'linkLabel',
          routerName: 'product-product-info-all',
          searchKey: 'productNo'
        },
        unitPrice: {
          label: '单价',
          showAuthName: 'order:unitprice:show'
        },
        orderProductNumberStr: {label: '订单数量'},
        putInStorageNumber: {label: '入库数量'},
        leaveStorageNumber: {label: '出库数量'},
        productWeightStr: {label: '订单克数'},
        productVolumeStr: {label: '订单容量'},
       // boxInfoList: {label: '纸箱', width: 150},
        remark: {label: '备注', width: 130},
        deviceId: {
          label: '上机',
          type: 'radio',
          items: [
            {value: 1, text: '1#-8单', tagType: 'danger'},
            {value: 2, text: '2#-8S',tagType: 'success'},
            {value: 3, text: '3#-8S'},
            {value: 4, text: '4#-9S',tagType: 'success'},
            {value: 5, text: '5#-8S',tagType: 'warning'},
            {value: 99, text: '待分配' ,tagType: 'info'},
            {value: 100, text: '外发' ,tagType: 'info'}
          ]
        },
        deepTypeStr: {label: '深加工'},
        manufacturerType: {
          label: '深加工在厂',
          type: 'radio',
          items: [
            {value: 0, text: '在玻璃厂',tagType: 'success'},
            {value: 1, text: '其他厂商', tagType: 'danger'}
          ]
        },
        deepProductImage: {label: '深加工样图', type: 'image',width: 95},
        deliveryTime: {label: '交货时间', type: 'date', width: 95},
        bottleCapSuit: {
          label: '瓶盖套装',
          type: 'radio',
          items: [
            {value: 0, text: '无', tagType: 'danger'},
            {value: 1, text: '有'}
          ]
        },
        // packRequire: {label: '包装要求'},
        boxPackImage: {label: '箱唛图片', type: 'image'},
        bottleInDiameter: {label: '瓶口内径'},
        headNeckHeight: {label: '头经高度'},
        bottleHeight: {label: '瓶高'},
        bottleOutDiameter: {label: '瓶口外径'},
        customerRequire: {label: '客户需求'},
        customerProductStyle: {
          label: '客户样品',
          type: 'radio',
          items: [
            {value: 0, text: '无', tagType: 'danger'},
            {value: 1, text: '有'}
          ]
        }
      }
    }
  },
  components: {
    tableView,
    multipleDialog
  },
  methods:{
    deliveryOrderDetail(id){
      console.info('id ' + id)
    },
    openOrderStatusDialog(order) {
      this.dialogVisible = true
      this.modifyOrder = order
      const {status} = order

      this.status = status
    },
    modifyOrderStatus() {
      if (this.modifyOrder.status === this.status) {
        return
      }
      this.modifyOrder.status = this.status

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.status = 0
        this.dialogVisible = false
        this.getDataList()
      })
    },
    adviceNoteFunc(rows) {
      this.onlineTime = ''

      this.tableListData = []
   //   this.initLicencePlateInfoList()

      for (let i = 0; i < rows.length; i++) {
        let _obj = {
          'orderDetailId': this.R.prop('id', rows[i]),
          'contractNo': this.R.prop('contractNo', rows[i]),
          'deliveryType': 0,
          'deliveryNumber': 0,
          orderNo: this.R.prop('orderNo', rows[i]),
          productNo : this.R.prop('productNo', rows[i]),
          clientName : this.R.prop('clientName', rows[i]),
          productWeight : this.R.prop('productWeight', rows[i]),
          unitPrice : this.R.prop('lightGlassPrice', rows[i]),
          orderProductNumber: this.R.prop('orderProductNumber', rows[i]),
          putInStorageNumber : this.R.prop('putInStorageNumber', rows[i]),
          leaveStorageNumber : this.R.prop('leaveStorageNumber', rows[i]),
          weightInfo : this.R.prop('weightInfo', rows[i]),
          deliveryAddress: this.R.prop('deliveryAddress', rows[i]),
          contractOrderId: this.R.prop('contractOrderId', rows[i]),
          productId: this.R.prop('productId', rows[i]),
          clientId : this.R.prop('clientId', rows[i])
        }
        this.tableListData.push(_obj)
      }
      this.$refs.multipleDialog.showOrderPlanNoticeDialog()
      console.log(this.tableListData)

    },
  }

}
</script>
